package com.example.shop_2210.utils

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
//@Interceptor(priority = 1)
class LoginInterceptor :IInterceptor {
    override fun init(context: Context?) {

    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        //根据实际情况判断是否要跳转到登录界面
        if("/app/LoginActivity".equals(postcard?.path)||
            "/app/LoginCodeActivity".equals(postcard?.path)||
            SPUtils.getInstance().getString("token").isNotEmpty()){
            //当要跳转的界面为登录界面或者已经登录的情况下 不需要跳转到登录界面
            //这些情况下不需要跳转到登录界面
            callback?.onContinue(postcard)
        }else{
            ARouter.getInstance().build("/app/LoginCodeActivity").navigation()
        }
    }
}